class CompletedPokerStack {
    constructor(pokerList = []) {
        this.pokerList = pokerList
        this.length = pokerList.length
    }
    push(...pokers) {
        for (let i = 0; i < pokers.length; i++) {
            this.pokerList.push(pokers[i])
        }
        let l = pokers.length
        this.length += l
        return this.length
    }
    pop() {
        this.length -= 1
        return this.pokerList.pop()
    }
    splice(n) {
        let a = this.pokerList.splice(n)
        this.length -= a.length
        return a
    }
    canPush(poker) {
        let { number, suit } = poker
        let length = this.pokerList.length
        if (length === 0 && number === 1) {
            return true
        }
        if (length !== 0) {
            let n = length - 1
            let lastPoker = this.pokerList[n]
            if (number === lastPoker.number + 1 && suit === lastPoker.suit) {
                return true
            }
        }
        return false
    }

    indexOf(poker) {
        let index = -1
        let pokerString = JSON.stringify(poker)
        for (let i = 0; i < this.pokerList.length; i++) {
            let s = JSON.stringify(this.pokerList[i])
            if (pokerString === s) {
                index = i
                break
            }
        }
        return index
    }
}